﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UcNestedPost.ascx.cs" Inherits="Fakebook.Shared.UcNestedPost" %>



<p>
    <asp:HiddenField ID="hfPostId" runat="server" />
</p>
<p>
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="PostId" 
        DataSourceID="postSource">
        
        
        <ItemTemplate>


            กระทู้ที่ <%#Eval("PostId")%>
            <%# Eval("Headline")%>
            <%--<asp:Image ID="fff" ImageUrl='<%#Eval("ImageUrl")%>' Width='128' Height='128' runat="server" />--%>
            <asp:HiddenField ID='hfImageUrl1' Value='<%#Eval("ImageUrl")%>' runat='server' />
            
            
         
            <a href='<%#Eval("iM") %>'>
                <%#Eval("FN") %>
            </a>
        </ItemTemplate>
    </asp:FormView>
    <asp:SqlDataSource ID="postSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
        SelectCommand="SELECT DISTINCT *, FN = REPLACE(ImageUrl,'~/Images/',''), iM = REPLACE(ImageUrl,'~','') FROM [Post] WHERE ([PostId] = @PostId)">
        <SelectParameters>
            <asp:ControlParameter ControlID="hfPostId" Name="PostId" PropertyName="Value" 
                Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <br />
</p>
<p>
    &nbsp;</p>



<asp:DataList ID="dl" runat="server" DataKeyField="AnswerId" 
    DataSourceID="answerSource">
    <ItemTemplate>
        <%--AnswerId:
        <asp:Label ID="AnswerIdLabel" runat="server" Text='<%# Eval("seq") %>' />
        <br />
        Detail:
        <asp:Label ID="DetailLabel" runat="server" Text='<%# Eval("Detail") %>' />
        <br />
        PostId:
        <asp:Label ID="PostIdLabel" runat="server" Text='<%# Eval("PostId") %>' />
        <br />
        CreatedDate:
        <asp:Label ID="CreatedDateLabel" runat="server" 
            Text='<%# Eval("CreatedDate") %>' />
        <br />
        UserId:
        <asp:Label ID="UserIdLabel" runat="server" Text='<%# Eval("UserId") %>' />
        
        <br />--%>

        ==== คำตอบที่ : <%# Eval("seq") %> ====================================================<br />
         <%#Eval("Detail")%>
        
    </ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="answerSource" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
    InsertCommand="INSERT INTO Answer(UserId, PostId, Detail) VALUES (NULL, @PostId, @Detail)" 
    SelectCommand="SELECT *, RANK() OVER(Partition by PostId Order by AnswerId) as seq FROM [Answer] WHERE ([PostId] = @PostId)">
    <InsertParameters>
        <asp:ControlParameter ControlID="hfPostId" Name="PostId" PropertyName="Value" />
        <asp:ControlParameter ControlID="txtPost" Name="Detail" PropertyName="Text" />
    </InsertParameters>
    <SelectParameters>
        <asp:ControlParameter ControlID="hfPostId" Name="PostId" PropertyName="Value" 
            Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
<p>
    <asp:TextBox ID="txtPost" runat="server"></asp:TextBox>
    <asp:Button ID="btnAnswer" runat="server" onclick="btnAnswer_Click" 
        Text="Answer" />
</p>
